﻿package org.cubeland.game.core.drawing.yuki
{
	import org.papervision3d.objects.DisplayObject3D;
	import caurina.transitions.Tweener;
	/**
	 * CubeLand.org Game
	 * @author Duarte Peixinho
	 */
	public class DrawYukiHeadContainer extends DisplayObject3D
	{
		private var _eyes:DrawYukiEyes;
		private var _head:DrawYukiHead;
		private var _leftHand:DrawYukiLeftHand;
		private var _rightHand:DrawYukiRightHand;
		
		private const TIME_MOVE:Number = 0.5;
		
		public function DrawYukiHeadContainer()
		{
			
			_eyes = new DrawYukiEyes();
			_head = new DrawYukiHead();
			_leftHand = new DrawYukiLeftHand();
			_rightHand = new DrawYukiRightHand();	
			
			_leftHand.x -= 70;
			_leftHand.z -= 40;
			_rightHand.z -= 40;
			_rightHand.x += 70;
			_eyes.z -= 60;
			_eyes.y += 30;				
		
			addChild(_head);
			addChild(_eyes);
			addChild(_leftHand);
			addChild(_rightHand);		
			
		}
		public function stop():void {
			_leftHand.rotationX = 0;
			_rightHand.rotationX = 0;
			_leftHand.rotationZ = 0;
			_rightHand.rotationZ = 0;	
			rotationZ = 0;
		}
		public function walk():void {
			leftHandUp();
			rightHandDown();
			headRight();
		}
		private function rightHandUp():void {
			Tweener.addTween(_rightHand,{time:TIME_MOVE,rotationX:50,transition:"linear" });	
		}
		private function leftHandUp():void{
			rightHandDown();
			Tweener.addTween(_leftHand,{time:TIME_MOVE,rotationX:50,onComplete:leftHandDown,transition:"linear"  });
		}
		private function leftHandDown():void{
			rightHandUp();
			Tweener.addTween(_leftHand,{time:TIME_MOVE,rotationX:-50,onComplete:leftHandUp,transition:"linear"  });
		}
		private function rightHandDown():void{
			Tweener.addTween(_rightHand,{time:TIME_MOVE,rotationX:-50,transition:"linear"  });
		}
		private function headRight():void {
			Tweener.addTween(this, { time:TIME_MOVE,rotationZ:-10,onComplete:headLeft,transition:"linear"  });
		}
		private function headLeft():void {
			Tweener.addTween(this, { time:TIME_MOVE,rotationZ:10,onComplete:headRight,transition:"linear"  });
		}
		public function lookLeft():void {
			_eyes.lookLeft();
		}
		public function lookRight():void {
			_eyes.lookRight();
		}
		public function lookUp():void {
			_eyes.lookUp();
		}
		public function lookDown():void {
			_eyes.lookDown();
		}
		public function lookCenter():void {
			_eyes.lookCenter();
		}
	}

}